﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.SelectedChatBots.Service
{
    public class SelectedChatBotAppService : BaseAppService, ISelectedChatBotAppService
    {
        private ISelectedChatBotDomainService _domainService;

        public SelectedChatBotAppService(ISelectedChatBotDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SELECTEDCHATBOT, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SELECTEDCHATBOT, AuditAction.CREATE)]
        public SelectedChatBotDto Add(SelectedChatBotCreateDto dto)
        {
            SelectedChatBot selectedChatBot = _domainService.Create(Mapper.Map<SelectedChatBot>(dto));
            return Mapper.Map<SelectedChatBotDto>(selectedChatBot);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SELECTEDCHATBOT, AuditAction.UPDATE)]
        public SelectedChatBotDto Update(SelectedChatBotUpdateDto dto)
        {
            SelectedChatBot selectedChatBot = _domainService.Update(Mapper.Map<SelectedChatBotUpdateBo>(dto));
            return Mapper.Map<SelectedChatBotDto>(selectedChatBot);
        }

        public SelectedChatBotDto Get(Guid id)
        {
            SelectedChatBot selectedChatBot = _domainService.Get(id);
            return Mapper.Map<SelectedChatBotDto>(selectedChatBot);
        }

        public IEnumerable<SelectedChatBotDto> GetList()
        {
            IEnumerable<SelectedChatBot> list = _domainService.List();
            return Mapper.Map<IEnumerable<SelectedChatBotDto>>(list);
        }
    }
}
